#ifndef BATTLE_VIEW_H
#define BATTLE_VIEW_H

#include <QWidget>
#include "DataPro/datapro.h"
#include "Charts/creatcharts.h"
// #include "Beans/psychologyindex.h"
#include "QTimer"
// #include "battlegroup.h"
#include "group_view.h"
#include "Report/reportdataforsort.h"
namespace Ui {
class Battle_view;
}

class Battle_view : public QWidget
{
    Q_OBJECT
enum COLUMN_NUM_E
{
    COLUMN_NO = 0,//排名名次
    COLUMN_NAME,//姓名
    COLUMN_SCORE //得分
};
typedef  struct USER_BATTLE_DATA_T
{
    QString IP;//IP地址
    QString sName;//用户姓名
    int score;//身心健康分数-贡献度，用作排名依据
}USER_BATTLE_DATA;

typedef QHash<QString, USER_BATTLE_DATA> QHashUserBattle;
typedef QHash<QString, USER_BATTLE_DATA>::iterator QHashUserBattleIterator;
public:
    explicit Battle_view(QWidget *parent = 0);
    ~Battle_view();
    void paintEvent(QPaintEvent *event);
    void initTableView_A();
    void initTableView_B();
    void initTableView_C();
    void initTableView_D();
    void RefreshTableA();
    void RefreshTableB();
    void RefreshTableC();
    void RefreshTableD();
    void initWaveViews();
    void initServer();
    void initSlots();
    double mean_List(QList<double>l);
    static bool  compareData(const ReportDataForSort &A1,const ReportDataForSort &A2);

private slots:
    void receivedMsg(QJsonObject & json);

    void addNewClient(QString);

    void removeClient(QString);

    void on_pushButton_exit_clicked();

    void getUserInfo(QHashUserTable A,QHashUserTable B,QHashUserTable C,QHashUserTable D,QString TaskID,QString Type,QString Scene,int Time);
    void update_a_Data();

    void on_pushButton_save_clicked();

private:
    Ui::Battle_view *ui;
    TableViewHeader *m_pTableHeader_Chlid;
    QStandardItemModel *m_pTableModel_A,*m_pTableModel_B,*m_pTableModel_C,*m_pTableModel_D;
    QHashUserTable m_userTableHash;

    QHashUserBattle m_userBattleHash_A;
    QHashUserBattle m_userBattleHash_B;
    QHashUserBattle m_userBattleHash_C;
    QHashUserBattle m_userBattleHash_D;

    QChart *abcd_Chart;
    QChart *abcdHist_BarChart;
    CreatCharts cc;
    QString TaskID;
    QString Type;
    QString Scene;
    int NeedTime;
    DataPro dataPro;
    QHashDataInfo hash_data_info_A,hash_data_info_B,hash_data_info_C,hash_data_info_D;
    QHash<QString ,int>Group_Label;//用于记录每组的ip属于哪一个组别
    QTimer *timer_UpdataChart;//更新平均图表
    QDateTime startTime;
    bool isAExit,isBExit,isCExit,isDExit;
    QList<double>PhysicalMentalHealth_list_A;
    QList<double>PhysicalMentalHealth_list_B;
    QList<double>PhysicalMentalHealth_list_C;
    QList<double>PhysicalMentalHealth_list_D;
signals:
    void command_toClient(int type,QJsonObject json);
};

#endif // BATTLE_VIEW_H
